package com.expense.app.admin.controller;

import com.expense.app.admin.annotation.IgnoreAuth;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import com.expense.common.util.Result;
import com.expense.app.admin.services.bmw.BmwStudentServ;
import com.expense.app.admin.model.params.bmw.bmwStudent.BmwStudentParam;
import com.expense.app.admin.model.params.bmw.bmwStudent.BmwStudentListParam;

import javax.validation.constraints.Min;

/*
*
* gen controller 2019-11-12
*/
@Validated
@RestController
@RequestMapping("/bmw/student")
public class BmwStudentCtrl {

    @Autowired
    BmwStudentServ bmwStudentServ;

    @GetMapping("/list")
    public Result findList(@Validated BmwStudentListParam param) {
        return Result.success(bmwStudentServ.findList(param));
    }

    @GetMapping(value = "/{id}")
    public Result findDetail (@PathVariable @Min(1) Long id) {
        return Result.success(bmwStudentServ.findDetail(id));
    }

    @PostMapping(value = "")
    public Result saveOne(@Validated @RequestBody BmwStudentParam param) {
        return Result.success(bmwStudentServ.saveOne(param));
    }

    @IgnoreAuth
    @PostMapping(value = "/web/save")
    public Result saveWebOne(@Validated @RequestBody BmwStudentParam param) {
        return Result.success(bmwStudentServ.saveOne(param));
    }

    @PutMapping(value = "")
    public Result update(@Validated @RequestBody BmwStudentParam param) {
        return Result.success(bmwStudentServ.saveOne(param));
    }

    @DeleteMapping(value = "/{id}")
    public Result deleteOne(@PathVariable @Min(0) Long id) {
        return Result.success(bmwStudentServ.deleteOne(id), true);
    }
}
